﻿///***************************************************************
/// 시  스  템 : Updms.Crd
/// 단위시스템 : CRD
/// 계      층 : Presentation Layer
/// 프로그램명 : Crd3011p
/// 파  일  명 : Crd3011p.aspx.cs
/// 설      명 : 계정별상세리스트(연간사용분석표에서 호출)
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2009-09-10 송시명   최초 작성
///***************************************************************
using System;
using System.Data;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;

using SMFramework.Data;
using SMFramework.Utility;
using SMFramework.Web.UI.WebControls.SMGridView;

using Base.Dac;
using Updms.Crd.Exe;


namespace Updms.Crd
{
    public partial class Crd3011p : Updms.Common.BaseClass.PageBase
    {
        #region 전역영역

		//프로그램상수
		public static readonly string PID = "Crd3011p";
		public static readonly string gs_path_info = "/updms/Crd/" + PID + ".aspx";

		Global global = new Global();
      
		//검색
		protected string kw1 = "";	//카드코드
		protected string kw2 = "";	//기준년월
		protected string kw3 = "";	//계정

		//항목별리스트 합계
		decimal ld_amount = 0;

        #endregion

        #region Page_Load, OnPageLoad

        protected void Page_Load(object sender, EventArgs e)
        {
            SetInit();
            if (!Page.IsPostBack)
            {
                // 최초 화면 로딩시 처리해야 할 부분
                OnPageLoad();
                SearchProcess();
            }
        }

        // OnPageLoad
        private void OnPageLoad()
        {
			SetLiterals(global.GetLabelInfoByPgmId(PID, LANG_SET));
            SetSearchParameter();
			ShowKeywordLabel();
        }

        #endregion

        #region InitializeComponent

        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);
            this.PreRender += new System.EventHandler(this.Page_PreRender);
        }

        #endregion       

        #region SetInit, SetSearchParameter, ShowKeywordLabel

        //초기값설정
        private void SetInit()
        {
        
        }

        //검색파라미터
        private void SetSearchParameter()
        {
            if (String.IsNullOrEmpty(Request.QueryString["kw1"]))	// url에 값이 없으면
            {
                kw1 = "CC01X";
            }
            else
            {
                kw1 = Server.UrlDecode(Request.QueryString["kw1"]);
            }
            if (String.IsNullOrEmpty(Request.QueryString["kw2"]))	// url에 값이 없으면
            {
                kw2 = DateUtil.GetNow("yyyy-MM");
            }
            else
            {
                kw2 = Server.UrlDecode(Request.QueryString["kw2"]);
            }
            if (String.IsNullOrEmpty(Request.QueryString["kw3"]))	// url에 값이 없으면
            {
                kw3 = "AC001X";
            }
            else
            {
                kw3 = Server.UrlDecode(Request.QueryString["kw3"]);
            }
        }

		//검색키워드
		private void ShowKeywordLabel()
		{
			lbl_search_keyword.Text = DateUtil.ConvertDateMask(kw2, "yyyy-MM", LANG_SET);
		}

        #endregion

        #region 마스터 Method ()

        #endregion

        #region 디테일 Method ()

        #endregion

        # region CRUD (SelectProcess, SearchProcess)

        //조회
        private void SelectProcess()
        {
            DataSet lo_ds = new DataSet();
            DataPack lo_dp = new DataPack();
          
            //검색
            lo_dp.AddProperty("ls_card_cd", typeof(string), kw1);
            lo_dp.AddProperty("ls_base_y_m", typeof(string), kw2);
            lo_dp.AddProperty("ls_account", typeof(string), kw3);
            lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

            using (Crd3011p_NT _Crd3011p_NT = new Crd3011p_NT())
            {
                lo_ds.Merge(_Crd3011p_NT.GetDetailListByAccount(lo_dp));

                GridView1.DataSource = lo_ds;
                GridView1.DataBind();
            }
        }
       
        //검색
        private void SearchProcess()
        {
            SetSearchParameter();
            SelectProcess();
        }

        #endregion

		#region Page_PreRender, ChangePageMode

		// Page_PreRender
		private void Page_PreRender(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				using (AccessCheck access = new AccessCheck())
				{
					//접근권한 체크
					if (!access.CheckPgmAccessGrant(PID, USER_ID, ACCESS_LOG_INFO))
					{
						Response.Redirect(URL_NO_AUTHORITY_REDIRECT_POPUP);	//사용자의 권한은 요청하신 페이지를 볼 수 없습니다
					}
				}
			}
			ChangePageMode();
		}

		// ChangePageMode
		private void ChangePageMode()
		{
			SetGridViewHeader(global.GetColumnListByPgmId(PID, LANG_SET));
		}

        #endregion

        #region GridView이벤트

        //RowDataBound
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				//마우스올렸을 때
				e.Row.Attributes.Add("onMouseOver", GRID_ONMOUSEOVER_COLOR);
				e.Row.Attributes.Add("onMouseOut", GRID_ONMOUSEOUT_COLOR);

				//번호
				e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();

				//페이지별 합계
				ld_amount += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Amount"));
			}

			//Footer에 합계 바인딩
			if (e.Row.RowType == DataControlRowType.Footer)
			{
				e.Row.Cells[0].Text = "Total";
				e.Row.Cells[0].Attributes.Add("class", "total");
				e.Row.Cells[0].ColumnSpan = 7;
				e.Row.Cells[1].Visible = false;
				e.Row.Cells[2].Visible = false;
				e.Row.Cells[3].Visible = false;
				e.Row.Cells[4].Visible = false;
				e.Row.Cells[5].Visible = false;
				e.Row.Cells[6].Visible = false;
				e.Row.Cells[7].Text = ld_amount.ToString("#,###,##0");
				e.Row.Cells[7].Attributes.Add("class", "money");
			}

			//머지
			SMGridView sGv = new SMGridView(this.Page, ref GridView1);
			sGv.RowSpanGridView(GridView1, 1);
			sGv.RowSpanGridView(GridView1, 2);
			sGv.RowSpanGridView(GridView1, 3);
        }

        //RowCommand
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            //Source
        }

        #endregion

        #region 버튼이벤트

        //검색
        protected void ibtn_search_Click(object sender, EventArgs e)
        {
            SearchProcess();
        }

        //엑셀
        protected void ibtn_excel_Click(object sender, EventArgs e)
        {
            SetSearchParameter();

            DataSet lo_ds = new DataSet();
            DataPack lo_dp = new DataPack();

            lo_dp.AddProperty("ls_card_cd", typeof(string), kw1);
            lo_dp.AddProperty("ls_base_y_m", typeof(string), kw2);
            lo_dp.AddProperty("ls_account", typeof(string), kw3);
            lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

            using (Crd3011p_NT _Crd3011p_NT = new Crd3011p_NT())
            {
                lo_ds.Merge(_Crd3011p_NT.GetDetailListByAccount(lo_dp));
			}
			string fileName = PID + "(" + global.GetMenuTitle(PID, LANG_SET) + ")";
			ExcelUtil.CreateExcelFileX(this.Page, fileName, lo_ds, SetExcelHeaderX(global.GetColumnListByPgmId(PID, LANG_SET)));
        }


        #endregion


    }
}
